package connectors;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;

/**
 * @author Lucas 'Mezmor' Pfister, Vishal Patel
 *
 */
public class Server extends Connection {
	
	ServerSocket serverConnector;
	
	public Server(int port) throws IllegalArgumentException {
		try {
			serverConnector = new ServerSocket(port);
			socketConnector = serverConnector.accept();
			outgoing = new PrintWriter(socketConnector.getOutputStream(), true);
			incoming = new BufferedReader(new InputStreamReader(socketConnector.getInputStream())); // DataInputStream incoming = new DataInputStream(new BufferedInputStream(socket.getInputStream())));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	@Override
	public boolean tearDown(){
		try {
			serverConnector.close();
			outgoing.close();
			incoming.close();
			socketConnector.close();
		} catch (IOException e) {
			e.printStackTrace();
			return false;
		}
		return true;
	}
	
	public String toString(){
		return "Server";
	}
}